package com.sunda.spmswms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sunda.spmswms.entity.Workshop;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 车间表 Mapper 接口
 * </p>
 *
 * @author Wayne
 * @since 2020-12-15
 */
@Mapper
@Component
public interface WorkshopMapper extends BaseMapper<Workshop> {

    @Select("SELECT ws.WERKS AS \"werks\",\n" +
            "       ws.WORKSHOP_CODE AS \"workshopCode\",\n" +
            "       ws.WORKSHOP_NAME_ZH AS \"workshopNameZh\",\n" +
            "       ws.WORKSHOP_NAME_EN AS \"workshopNameEn\",\n" +
            "       ws.WORKSHOP_DESC AS \"workshopDesc\"\n" +
            " FROM WORKSHOP ws WHERE ws.WERKS = #{werks}")
    List<Map<String, Object>> getWorkshopByWerks(@Param("werks") String werks);

    @Select("SELECT WE.WERKS AS \"werks\",\n" +
            "       WE.WERKS_NAME_EN AS \"werksNameEn\",\n" +
            "       WE.WERKS_NAME_ZH AS \"werksNameZh\",\n" +
            "       WE.COMPANY_CODE AS \"companyCode\",\n" +
            "       WE.COMPANY_NAME_EN AS \"companyNameEn\",\n" +
            "       WE.COMPANY_NAME_ZH AS \"companyNameZh\",\n" +
            "       WE.REGIO_GROUP AS \"regioGroup\",\n" +
            "       WE.COUNTRY AS \"country\",\n" +
            "       WO.WORKSHOP_CODE AS \"workshopCode\",\n" +
            "       WO.WORKSHOP_NAME_EN AS \"workshopNameEn\",\n" +
            "       WO.WORKSHOP_NAME_ZH AS \"workshopNameZh\",\n" +
            "       WO.WORKSHOP_DESC AS \"workshopDesc\"\n" +
            "FROM WERKS WE LEFT JOIN WORKSHOP WO ON WE.WERKS = WO.WERKS " +
            "WHERE WO.WORKSHOP_CODE IS NOT NULL " +
            "ORDER BY WE.WERKS, WO.WORKSHOP_CODE ASC\n")
    List<Map<String, Object>> getAllWorkshop();
}
